package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class JDBCDemo11 {
    public static void main(String[] args) {
        try (
                Connection connection = DBUtil.getConnection()
        ) {
            Scanner scan=new Scanner(System.in);
            System.out.println("请输入查找用户名：");
            String userName = scan.nextLine();
            System.out.println("请输入要修改的密码：");
            String passWord = scan.nextLine();
            connection.setAutoCommit(false);
            connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
            String sql="UPDATE user SET password=? WHERE username=?";
            PreparedStatement ps= connection.prepareStatement(sql);
            ps.setString(1, passWord);
            ps.setString(2, userName);
            int num=ps.executeUpdate();
            System.out.println(num>0?"修改成功":"修改失败");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
